package org.charles.zhifou.common.response;

import lombok.Data;

import java.io.Serializable;

/**
 * <h1>通用返回类</h1>
 *
 * @author charles
 * @version 1.0
 */
@Data
public class BaseResponse<T> implements Serializable {

    private Integer code;

    private T data;

    private String message;

    // 根据 code 是数字还是枚举类, data 和 message 参数是否存在, 写 8 个重载方法

    public BaseResponse(Integer code, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public BaseResponse(Integer code, T data) {
        this(code, data, "");
    }

    public BaseResponse(Integer code, String message) {
        this(code, null, message);
    }

    public BaseResponse(Integer code) {
        this(code, null, "");
    }

    public BaseResponse(ResponseCodeEnum responseCodeEnum, T data, String message) {
        this(responseCodeEnum.getCode(), data, message);
    }

    public BaseResponse(ResponseCodeEnum responseCodeEnum, T data) {
        this(responseCodeEnum.getCode(), data, responseCodeEnum.getValue());
    }

    public BaseResponse(ResponseCodeEnum responseCodeEnum, String message) {
        this(responseCodeEnum.getCode(), null, message);
    }

    public BaseResponse(ResponseCodeEnum responseCodeEnum) {
        this(responseCodeEnum.getCode(), null, responseCodeEnum.getValue());
    }
}
